using System;
using Sixeyed.CodeGeneration.Metadata.Interfaces;

namespace Sixeyed.CodeGeneration.Metadata.Bases
{
    /// <summary>
    /// Abstract base class for metadata items
    /// </summary>
    /// <typeparam name="TItemType">Underlying metadata object type</typeparam>
    public abstract class ItemBase<TItemType> : IMetadataItem
        where TItemType : class
    {
        #region Private instance fields

        private IMetadataProvider _provider;
        private string _key;
        private TItemType _item;

        #endregion

        #region Public properties

        /// <summary>
        /// Metadata provider
        /// </summary>
        public IMetadataProvider Provider
        {
            get { return this._provider; }
            set { this._provider = value; }
        }

        /// <summary>
        /// Unique identifying key for the item
        /// </summary>
        public virtual string Key 
        {
            get { return this._key; }
            set { this._key = value; }
        }        

        /// <summary>
        /// Typed representation of underlying metadata object
        /// </summary>
        public TItemType TypedItem
        {
            get { return _item; }
            set { _item = value; }
        }

        /// <summary>
        /// Underlying metadata object
        /// </summary>
        public object Item
        {
            get { return this._item as object; }
            set { this._item = (TItemType) value; }
        }

        /// <summary>
        /// Type of underlying metadata object
        /// </summary>
        public Type ItemType
        {
            get { return typeof(TItemType); }
        }

        #endregion
    }
}
